home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / util2 / pgp22src.zip / CONTRIB / ELM_NN / MAILPGP next >
Text File  |  1993-03-07  |  2KB  |  116 lines

  1. #!/usr/bin/perl
  2.  
  3. ($visual = $ENV{'VISUAL'}) || ($visual = '/usr/ucb/vi');
  4. $topgp = 0;
  5. $blanks = 0;
  6. $paragraphs = 1;
  7. $blankcompress = 1;
  8. $name=@ARGV[$#ARGV];
  9. umask (077);
  10. open (INPUT, "<$name");
  11. open (OUTPUT, ">${name}.rply") || die "Cannot open ${name}.rply for output.\n";
  12. while (<INPUT>) {
  13.     if (!$topgp && !m/^> -----BEGIN PGP .*-----/) {
  14.         if (m/^> *$/) {
  15.             if ($paragraphs) {
  16.                 if ($blankcompress) {
  17.                     if ($blanks == 0) {
  18.                         print OUTPUT "\n";
  19.                         $blanks = 1;
  20.                     }
  21.                 } else {
  22.                     print OUTPUT "\n";
  23.                 }
  24.             } else {
  25.                 print OUTPUT;
  26.             }
  27.         } elsif (m/^ *$/) {
  28.             if ($blankcompress) {
  29.                 if ($blanks == 0) {
  30.                     print OUTPUT "\n";
  31.                     $blanks = 1;
  32.                 }
  33.             } else {
  34.                 print OUTPUT;
  35.             }
  36.         } else {
  37.             print OUTPUT;
  38.             if ($. == 1 && !m/^> /) {
  39.                 print OUTPUT "\n";
  40.                 $blanks = 1;
  41.             } else {
  42.                 $blanks = 0;
  43.             }
  44.         }
  45.     }
  46.     if (!$topgp && m/^> -----BEGIN PGP .*-----/) {
  47.         $topgp = 1;
  48.         $tmpfile = "${name}.pgp",
  49.         unlink ($tmpfile);
  50.         open (TMPFILE, ">$tmpfile") || die "Cannot open $tmpfile for output.\n";
  51.     }
  52.     if ($topgp) {
  53.         $_ =~ s/^> //;
  54.         print TMPFILE $_;
  55.         if (m/^-----END PGP .*-----/) {
  56.             $topgp = 0;
  57.             close TMPFILE;
  58.             $clrfile = "${name}.clr";
  59.             `pgp $tmpfile -o $clrfile`;
  60.             open (CLEAR, "<$clrfile") || die "Cannot open $clrfile for input.\n";
  61.             print OUTPUT "-----BEGIN OF PGP DECRYPTED TEXT-----\n\n";
  62.             while (<CLEAR>) {
  63.                 if (m/^$/) {
  64.                     print OUTPUT "\n";
  65.                 } else {
  66.                     print OUTPUT "> ";
  67.                     print OUTPUT;
  68.                 }
  69.             }
  70.             close CLEAR;
  71.             unlink ($clrfile);
  72.             unlink ($tmpfile);
  73.             print OUTPUT "\n-----END OF PGP DECRYPTED TEXT-----\n\n";
  74.         }
  75.     }
  76. }
  77. close OUTPUT;
  78. close INPUT;
  79. unlink ($name);
  80. rename ("${name}.rply", "$name");
  81.  
  82. system ($visual,@ARGV);
  83.  
  84. while (!$q) {
  85.     print "Sign this message? [Y]: ";
  86.     $q = <STDIN>;
  87.     $q =~ s/[ \t\n]//g;
  88.     $q = substr ($q, 0, 1);
  89.     if (($q eq 'Y') || ($q eq 'y') || ($q eq '')) {
  90.         push(@opts,'-st','+clearsig=on');
  91.         $q = "y";
  92.     } elsif (($q ne 'N') && ($q ne 'n')) {
  93.         $q = '';
  94.     }
  95. }
  96. $q='';
  97. while (!$q) {
  98.     print "Encrypt this message? [Y]: ";
  99.     $q = <STDIN>;
  100.     $q =~ s/[ \t\n]//g;
  101.     $q = substr ($q, 0, 1);
  102.     if (($q eq 'Y') || ($q eq 'y') || ($q eq '')) {
  103.         push(@opts,'-e');
  104.         $q = "y";
  105.     } elsif (($q ne 'N') && ($q ne 'n')) {
  106.         $q = '';
  107.     }
  108. }
  109. if (@opts) {
  110.     system ('pgp','-a',@opts,$name);
  111.     if ($? == 0) {
  112.         unlink ${name};
  113.         rename ("${name}.asc", "$name");
  114.     }
  115. }
  116.